home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15222 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  42 lines

  1. Newsgroups: comp.lang.c++
  2. Path: artemis.sto.fdata.se!news
  3. From: Niklas Mellin <niklas.mellin@sto.fdata.se>
  4. Subject: Re: Operators <<= and >>=
  5. Sender: news@artemis.sto.fdata.se (UseNet NetNews)
  6. Message-ID: <31638745.65B8@sto.fdata.se>
  7. Date: Thu, 4 Apr 1996 08:24:37 GMT
  8. Content-Transfer-Encoding: 7bit
  9. Content-Type: text/plain; charset=us-ascii
  10. References: <4iva5m$4q5@access4.digex.net> <Pine.OSF.3.91.960403110722.17337E-100000@bud.cc.swin.edu.au>
  11. Mime-Version: 1.0
  12. X-Mailer: Mozilla 2.0 (WinNT; I)
  13. Organization: WM-data F÷rsvarsdata AB, Sweden
  14.  
  15. John Joseph Newbigin wrote:
  16. > On 22 Mar 1996, Mr. Blue wrote:
  17. > >
  18. > > When / why would one overload the operators <<= and >>=  ?
  19. > Much greater(or less) that or equal?
  20.  
  21. operator <<= means left shift of left operand for built in
  22. types, and operator >>= means right shift
  23.  
  24. int foo = 3; // 00000011
  25. //shift bits in foo 2 places to the left
  26. foo <<= 2;   // 00001100
  27.  
  28. I can imagine they can be useful when you have a class representing
  29. some kind of bit pattern, but I have never overloaded those operators
  30. in production code.
  31.  
  32. Overloading operators is an important feature in C++, if used correctly
  33. it can make your programs much more readable. But used correctly also
  34. means that you should not overload every possible operator just because
  35. the language lets you.
  36.  
  37. ---
  38. Niklas Mellin
  39.